﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data.MySqlClient;
namespace test
{
    public class DBHelper
    {
        //private String connString = @"Data Source=.;Initial Catalog=Su;User Id=root;Pwd=123456";
        String connString = "server=127.0.0.1;port=3306;user=root;password=123456; database=su;";
        private MySqlConnection connection;
        /// <summary>
        /// 连接对象
        /// </summary>
        public MySqlConnection Connection {
            get
            {
                if (connection == null)
                {
                    connection = new MySqlConnection(connString);
                }
                return connection;
            }
         }
        ///<summary>
        ///打开数据库连接
        /// </summary>
        public void OpenConnection()
        {
            if (Connection.State == ConnectionState.Closed)
            {
                Connection.Open();
            }
            else if (Connection.State == ConnectionState.Broken)
            {
                Connection.Close();
                Connection.Open();
            }
        }
        ///关闭数据库
        public void CloseConnection()
        {
            if (Connection.State == ConnectionState.Open ||Connection.State==ConnectionState.Broken)
            {
                Connection.Close();
            }
        }

        internal void ExecuteNonQuery()
        {
            throw new NotImplementedException();
        }
    }
}
